home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 5.2 KB | 167 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- mapper.sx
-
- -- Other Files Required:
- -- mapwin.sx, mapdoc.sx
-
- -- Purpose:
- -- Class definition for the Mapper class.
-
- -- Specialized Classes:
- -- Mapper
-
- -- Instructions to User:
- -- Class Mapper is a TwoDSpace which is used to display the location of objects are on a
- -- map. The current implementation is specific to the map in the AutoFinder title (some
- -- attempt has been made at generality). All objects are represented by a push pin. When
- -- the pin is clicked, the editObject method is invoked on self, which brings up a detail
- -- window with a MapDocument for that object. If the detail is already displayed, it simply
- -- sets the target of the document to the selected object.
-
- -- Author:
- -- Steve Mayer
-
- in module Autofinder
-
- if (NOT isdefined detailWindow) do filein theScriptDir name:"mapwin.sx"
-
- class Mapper (TwoDSpace)
- instance variables
- media
- detailMaps
- quadrantWidth -- Width of a quadrant on the big map.
- quadrantHeight -- Height of a quadrant on the big map.
- detailWidth -- Width of a detail map.
- detailHeight -- Height of a detail map.
- detailDocument
- control
- end
-
- method init self {class Mapper} #rest args #key manager: media: \
- quadrantWidth: (40) quadrantHeight: (40) detailWidth: (368) \
- detailHeight: (276) ->
- (
- apply nextMethod self args
- self.stroke := whiteBrush
- self.detailDocument := undefined
- self.quadrantWidth := quadrantWidth
- self.quadrantHeight := quadrantHeight
- self.detailWidth := detailWidth
- self.detailHeight := detailHeight
- local ac := new ActuatorController space:self wholeSpace:true
- local dc := new DragController space:self wholeSpace:true
- self.control := #(ac, dc)
- prepend self media["map"]
- self.media := media
-
- initDetailMaps self
- return self
- )
-
- method leaveScene self {class Mapper} ->
- (
- for i in self.control do
- i.space := undefined
- emptyout self.control
-
- emptyout self
- for i in self.detailMaps do
- makePurgeable i
- )
-
- method initDetailMaps self {class Mapper} ->
- (
- -- Detail mapping maps rectangles on the big map to detail maps.
- self.detailMaps := new KeyedLinkedList
- add self.detailMaps (11 * 100 + 11) self.media["Woodside"]
- add self.detailMaps (4 * 100 + 10) self.media["Halfmoon Bay"]
- add self.detailMaps (10 * 100 + 5) self.media["San Mateo"]
- add self.detailMaps (5 * 100 + 4) self.media["Hillsborough"]
- add self.detailMaps (10 * 100 + 7) self.media["Belmont"]
- add self.detailMaps (11 * 100 + 7) self.media["Redwood City"]
- )
-
- method getDetail self {class Mapper} mapPoint ->
- (
- -- Calculate which quadrant the point is in.
- local quadrantX := ((mapPoint.x / self.quadrantWidth) as Integer) + 1
- local quadrantY := ((mapPoint.y / self.quadrantHeight) as Integer) + 1
-
- -- Use the quadrant as an index into the detail maps.
- local detailMap := self.detailMaps[quadrantX * 100 + quadrantY]
-
- -- Calculate detail map location, and add a push pin there.
- local detailX := ((mod mapPoint.x self.quadrantWidth) * self.detailWidth) / self.quadrantWidth
- local detailY := ((mod mapPoint.y self.quadrantHeight) * self.detailHeight) / self.quadrantHeight
- local pushPin := new TwoDShape boundary:self.media["pushpin"] fill:blackBrush
- translate pushPin.transform detailX detailY
-
- -- Create a TwoDMultipresenter for the detail map and the push pin.
- local detail := new TwoDMultiPresenter boundary:detailMap.boundary
- prepend detail detailMap
- prepend detail pushPin
- return detail
- )
-
- method editObject self {class Mapper} button ->
- (
- button.target.mapPresenter := getDetail self button.target.location
-
- -- If there is no detail map document, create one and add it to a palette window.
- if (self.detailDocument = undefined) then
- (
- -- Note, Due to Win '95 bug, detailWidth and detailHeight
- -- had to be changed to multiple of 4. Should be 365, 274.
- local d := new MapDocument boundary:(new Rect x2:self.detailWidth y2:self.detailHeight) \
- media:self.media target:button.target
- self.detailDocument := d
- local detailWin := new detailWindow parentDoc:self media:self.media \
- boundary:(new Rect x2:self.detailWidth y2:self.detailHeight) \
- name:"Car Detail" title:theTitleContainer centered:true
- prepend detailWin d
- show detailWin
-
- )
- -- Otherwise, change the target of the existing detail document.
- else
- (
- self.detailDocument.target := button.target
- show self.detailDocument.presentedBy
- )
- goTo self.detailDocument 1
- )
-
- -- Method addObject adds a map representation of an object to self.
- method addObject self {class Mapper} obj ->
- (
- -- Create a map presenter for the specified object, and add it to the map.
- local pin := self.media["pushpin"]
- local rp := new TwoDShape boundary:pin fill:blackBrush
- local pp := new TwoDShape boundary:pin fill:blackBrush
- local mp := new PushButton releasedPresenter:rp pressedPresenter:pp
-
- -- Get mapPresenter's position, and prepend to the map.
- mp.x := obj.location.x
- mp.y := obj.location.y
- mp.target := obj
- mp.authorData := self
- mp.activateAction := editObject
- prepend self mp
- )
-
- -- Method addManyObjects adds every member of a collection to self.
- method addManyObjects self {class Mapper} a ->
- (
- for obj in a do addObject self obj
- )
-
- -- Method getScale is used by tools to query the scale of the space.
- method getScale self {class Mapper} ->
- (
- return #(#("Miles", 17))
- )
-
- -->>>
- "Compiled mapper.sx"
-